package com.ruoyi.project.orderSystem.controller;

import java.util.List;

import com.ruoyi.project.orderSystem.domain.WorkOrder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.orderSystem.domain.WorkOrderAudit;
import com.ruoyi.project.orderSystem.service.IWorkOrderAuditService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 工单审核主Controller
 * 
 * @author wangshuo
 * @date 2021-03-04
 */
@RestController
@RequestMapping("/orderSystem/workOrderAudit")
public class WorkOrderAuditController extends BaseController
{
    @Autowired
    private IWorkOrderAuditService workOrderAuditService;

    /**
     * 查询工单审核主列表
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrderAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkOrderAudit workOrderAudit)
    {
        startPage();
        List<WorkOrderAudit> list = workOrderAuditService.selectWorkOrderAuditList(workOrderAudit);
        return getDataTable(list);
    }

    /**
     * 查询工单待审核主列表
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrderUnAudit:list')")
    @GetMapping("/workOrderUnAudit")
    public TableDataInfo workOrderUnAudit(WorkOrder workOrder)
    {
        startPage();
        List<WorkOrder> list = workOrderAuditService.workOrderUnAudit(workOrder);
        return getDataTable(list);
    }

    /**
     * 导出工单审核主列表
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrderAudit:export')")
    @Log(title = "工单审核主", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkOrderAudit workOrderAudit)
    {
        List<WorkOrderAudit> list = workOrderAuditService.selectWorkOrderAuditList(workOrderAudit);
        ExcelUtil<WorkOrderAudit> util = new ExcelUtil<WorkOrderAudit>(WorkOrderAudit.class);
        return util.exportExcel(list, "workOrderAudit");
    }

    /**
     * 获取工单审核主详细信息
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrderAudit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workOrderAuditService.selectWorkOrderAuditById(id));
    }

    /**
     * 新增工单审核主
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrderAudit:add')")
    @Log(title = "工单审核主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkOrderAudit workOrderAudit)
    {
        return toAjax(workOrderAuditService.insertWorkOrderAudit(workOrderAudit));
    }

    /**
     * 新增工单审核主
     */
    @Log(title = "工单审核", businessType = BusinessType.INSERT)
    @PostMapping("/auditWorkOrder")
    public AjaxResult auditWorkOrder(@RequestBody WorkOrderAudit workOrderAudit)
    {
        return toAjax(workOrderAuditService.auditWorkOrder(workOrderAudit));
    }

    /**
     * 修改工单审核主
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrderAudit:edit')")
    @Log(title = "工单审核主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkOrderAudit workOrderAudit)
    {
        return toAjax(workOrderAuditService.updateWorkOrderAudit(workOrderAudit));
    }

    /**
     * 删除工单审核主
     */
    @PreAuthorize("@ss.hasPermi('orderSystem:workOrderAudit:remove')")
    @Log(title = "工单审核主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workOrderAuditService.deleteWorkOrderAuditByIds(ids));
    }
}
